<!--Copyright (C) Kherty.  All rights reserved.-->
<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:drawing2="clr-namespace:OpenLS.Drawing.UI;assembly=OpenLS.Drawing.UI" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ss="http://schemas.Kherty.com/office/2007/spreadsheet" 
    xmlns:ssui="clr-namespace:OpenLS.Spreadsheet.UI" 
    xmlns:Internals="clr-namespace:OpenLS.Spreadsheet.UI.Internals" 
    x:Class="OpenLS.Spreadsheet.UI.Internals.EditedCellResources"
    >
  <ResourceDictionary.MergedDictionaries>
            <Internals:ReflectionResources></Internals:ReflectionResources>
            <ssui:EditedCellColors/>
    <ssui:WorksheetResourcesHelpers/> <!-- change name-->
        <Internals:FunctionResources/>
    </ResourceDictionary.MergedDictionaries>
    
    <Style TargetType="{x:Type Grid}" x:Key="editedCellGridStyle">
        <Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
        <Setter Property="VerticalAlignment" Value="Stretch"></Setter>
        <Setter Property="TextElement.FontStyle" Value="{Binding Path=Cell.FontStyle}"></Setter>
        <Setter Property="TextElement.FontWeight" Value="{Binding Path=Cell.FontWeight}"></Setter>
        <Setter Property="TextElement.FontFamily" Value="{Binding Path=Cell.FontFamily}"></Setter>
        <Setter Property="TextElement.FontSize" Value="{Binding Path=Cell.FontSize, Converter={x:Static ss:PointsToPixelConverter.Instance}}" />
    	<Setter Property="VerticalAlignment" Value="Stretch" />
        <Setter Property="Background">
            <Setter.Value>
                <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.EnsureWhiteConverter}">
                    <Binding Path="Cell.ActualBackground" />
                    <Binding RelativeSource="{RelativeSource Self}" Path="(drawing2:DrawingElement.ColorScheme)"/>
                </MultiBinding>
            </Setter.Value>
        </Setter>
        <Setter Property="Visibility">
            <Setter.Value>
                <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.MultiEqualConverter}">
                    <Binding Path="Cell.Worksheet"/>
                    <Binding Path="(ssui:SpreadsheetElement.Worksheet)" RelativeSource="{RelativeSource Self}"/>
                </MultiBinding>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type Internals:CellTextBox}" x:Key="editedCellTextBoxStyle">
        <Setter Property="Margin" Value="0"></Setter>
        <Setter Property="Padding" Value="0"></Setter>
        <Setter Property="EditedCell" Value="{Binding}"></Setter>
        <Setter Property="ColorScheme" Value="{Binding RelativeSource={RelativeSource Self}, Path=(drawing2:DrawingElement.ColorScheme)}"></Setter>
        <Setter Property="ssui:SpreadsheetElement.Formula" Value="{Binding Formula}"></Setter>
        <Setter Property="HorizontalAlignment" Value="Left"></Setter>
        <Setter Property="VerticalAlignment" Value="{Binding Path=Cell.VerticalAlignment, Converter={x:Static Internals:SpreadsheetConverters.VerticalCellAlignmentConverter}}"></Setter>
        <Setter Property="Internals:FocusElement.AutoFocus" Value="True"></Setter>
        <Setter Property="Background">
            <Setter.Value>
                <MultiBinding Converter="{x:Static Internals:SpreadsheetConverters.EnsureWhiteConverter}">
                    <Binding Path="Cell.ActualBackground"></Binding>
                    <Binding RelativeSource="{RelativeSource Self}" Path="(drawing2:DrawingElement.ColorScheme)"/>
                </MultiBinding>
            </Setter.Value>
        </Setter>
        <EventSetter Event="PreviewKeyDown" Handler="onPreviewKeyDown"></EventSetter>
        <EventSetter Event="ss:SpreadsheetElement.CommittingText" Handler="onCommittingText"></EventSetter>
    </Style>

    <DataTemplate DataType="{x:Type Internals:EditedCell}">
        <ssui:PopupPanel Internals:EditionElement.Selector="{Binding ElementName=functionListBox}">
            <Grid Name="cellGrid" Style="{StaticResource editedCellGridStyle}">
                <Internals:GridCellTextBox Style="{StaticResource editedCellTextBoxStyle}" 
                   x:Name="editedCellTB" Tag="1" >
                </Internals:GridCellTextBox>
            </Grid>
            <!--<ContentPresenter Focusable="True" Content="{Binding}" Name="editedKeyHolder"/> -->
           <ListBox ItemsSource="{Binding FunctionSuggestions}" 
                    MaxHeight="180" Name="functionListBox" Tag="{Binding ElementName=editedCellTB}" MouseDoubleClick="functionListBox_MouseDoubleClick" KeyDown="functionListBox_KeyDown"/>
            <Border TextElement.FontSize="14" HorizontalAlignment="Left" BorderBrush="#767676" BorderThickness="1" CornerRadius="2" Name="method"
                    Loaded="onBorderLoaded">
                <Border.Background>
                    <LinearGradientBrush StartPoint="0 0" EndPoint="0 1">
                        <GradientStop Color="White"></GradientStop>
                        <GradientStop Color="#D2DfF1" Offset="1"/>
                    </LinearGradientBrush>
                </Border.Background>
                <ContentPresenter Content="{Binding CurrentParameter}" Margin="3 0 3 0"/>
            </Border>
        </ssui:PopupPanel>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding CurrentParameter}" Value="{x:Null}">
                <Setter TargetName="method" Property="Visibility" Value="Collapsed"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding FunctionSuggestions}" Value="{x:Null}">
                <Setter TargetName="functionListBox" Property="Visibility" Value="Collapsed"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding FunctionSuggestions.Count}" Value="0">
                <Setter TargetName="functionListBox" Property="Visibility" Value="Collapsed"/>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
  <DataTemplate DataType="{x:Type Internals:EditedCell}" x:Key="FormulaEditedCell">
            <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="White">
            <ScrollViewer HorizontalScrollBarVisibility="Hidden" CanContentScroll="True" VerticalScrollBarVisibility="Auto" Name="formulaScrollViewer">
                <Internals:FormulaCellTextBox EditedCell="{Binding}" PreviewKeyDown="OnPreviewKeyDownInFormula" DataContext="{Binding}" 
               x:Name="editedCellTB"  Tag="4" 
                                                          ColorScheme="{Binding RelativeSource={RelativeSource Self}, Path=(drawing2:DrawingElement.ColorScheme)}"

               Margin ="1 0 0 0" Padding="0"
               TextAlignment="Left" 
               HorizontalAlignment="Stretch" 
               VerticalAlignment ="Stretch" 
               Background="White" 
               BorderThickness="0" />
            </ScrollViewer>
        </Grid>
    </DataTemplate>

  
</ResourceDictionary>